﻿using System;
using System.Collections.Generic;
using System.Linq;
using VkApiVer2.api.Enums;
using VkApiVer2.extensions;

namespace VkApiVer2.api.Utils
{

    public static class RightsUtils
    {
        public static String GetMaxRights()
        {
            return string.Join(",", GetRightsString());
        }

        public static IEnumerable<string> GetRightsString()
        {
            return from Right right
                   in Enum.GetValues(typeof(Right))
                   select right.ToString().ToLower();
        }


        public static String ConvertRightsToString(Right fields)
        {
            return string.Join(",", GetCheckedRightsString(fields));
        }

        public static String GetAllRights()
        {
            return string.Join(",", GetAllRightsString());
        }

        private static IEnumerable<string> GetAllRightsString()
        {
            foreach(string right in Enum.GetNames(typeof(Right)))
                yield return right.ToLower();
        }

        private static IEnumerable<string> GetCheckedRightsString(Right rights)
        {
            foreach(Right value in Enum.GetValues(typeof(Right)))
            {
                if(!rights.IsSet(value)) continue;
                yield return Enum.GetName(typeof(Right), value).ToLower();
            }
        }
    }

}
